package operations;

import java.util.Scanner;
import aboutTheBook.Book;
import aboutTheBook.BookShelf;

public class Modify implements IOperation,ICheckIsEmpty{
    @Override
    public boolean checkIsEmpty(BookShelf bookShelf) {
        return bookShelf.getSize()==0;
    }
    @Override
    public void work(BookShelf bookShelf) {
        if(checkIsEmpty(bookShelf)) {
            System.out.println("书架为空，无法进行修改！");
            return;
        }
        //管理员操作
        //对pos位置元素进行修改
        System.out.println("请输入需要修改的元素下标：");
        Scanner scanner = new Scanner(System.in);
        int index = scanner.nextInt();

        if(index<bookShelf.getSize() && index >= 0) {
            String tmp = scanner.nextLine();
            System.out.println("请输入您修改后的书籍类型：");
            String bookType = scanner.nextLine();
            System.out.println("请输入您修改后的书籍名称：");
            String title = scanner.nextLine();
            System.out.println("请输入您修改后的书籍作者：");
            String author = scanner.nextLine();
            System.out.println("请输入该书修改后的存放地点：");
            String location = scanner.nextLine();
            Book book = new Book(bookType,title,author,location);
            bookShelf.setPosBook(index,book);
            System.out.println("修改成功！");
        } else {
            System.out.println("抱歉，您输入的下标有越界风险，请重新输入！");
        }
    }
}
